package org.graduates.webapp.actions.utils;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.graduates.webapp.actions.BaseAction;
import org.projects.graduates.domain.User;

@Action(results = { @Result(name = "success", type = "json") })
public class ExistUsernameAction extends BaseAction {
	private static final long serialVersionUID = 2519819753551113610L;

	private String username;

	private boolean exist = true;

	private boolean success = false;

	public String execute() {

		if (StringUtils.isEmpty(username)) {
			return SUCCESS;
		}

		User user = this.secApplication.findby(username);

		exist = null == user ? false : true;

		success = true;

		return SUCCESS;
	}

	public boolean isSuccess() {
		return success;
	}

	public boolean isExist() {
		return exist;
	}

	public void setUsername(String username) {
		this.username = username;
	}

}
